package com.itrip.config;

import com.itrip.filter.HeaderFilter;
import com.itrip.filter.LoginFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class FilterConfig {

    @Resource
    private HeaderFilter headerFilter;

    @Resource
    private LoginFilter loginFilter;

    @Bean
    public FilterRegistrationBean<HeaderFilter> enCodeFilterSet(){
        FilterRegistrationBean<HeaderFilter> filterRegistrationBean=new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(headerFilter);
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setOrder(1);
        return filterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean<LoginFilter> LoginFilterSet(){
        FilterRegistrationBean<LoginFilter> filterRegistrationBean=new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(loginFilter);
        filterRegistrationBean.addUrlPatterns("/view/*");
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }

}
